************** Making the dofile used for analysis **************
//set working directory
global path ""

cd "$path/Original Excel_Files"

//importing data on Ambiguity dimensions
import excel "uncertainty--apr24.xlsx", sheet("Ark1") firstrow

//renaming the variable country_code (which is used for merging)
generate str iso3 = country_code
drop country_code

//inserting the EU values for all EU member countries.

foreach i in AUT BEL BGR CYP CZE DEU DNK ESP EST FIN FRA GRC HRV HUN IRL ITA LTU LUX LVA MLT NLD /// 
POL PRT ROU SVK SVN SWE {
	set obs `=_N+1'
	replace iso3="`i'" if iso3=="" 
}

replace iso3="A" if iso3=="EU"
sort iso3

//Inserting the EU variables
qui ds
local all `r(varlist)'
local names country_name iso3
local ambiguity: list all - names 

foreach var in `ambiguity' {
foreach i in AUT BEL BGR CYP CZE DEU DNK ESP EST FIN FRA GRC HRV HUN IRL ITA LTU LUX LVA MLT NLD /// 
POL PRT ROU SVK SVN SWE {
	replace `var'=`var'[1] if iso3=="`i'"
}
}

replace iso3="EU" if iso3=="A"

//See if it worked
sort type_of_target_class-g20_details
quietly by type_of_target_class-g20_details:  gen dup = cond(_N==1,0,_n)
tab dup

cd "$path/New datasets"
save Ambiguity.dta, replace

clear all

//importing the data containing control variables and ambition data
cd "$path/Original Excel_Files"
import excel "ambition-controls-apr24.xlsx", sheet("sheet1") firstrow

cd "$path/New datasets"
merge 1:1 iso3 using Ambiguity.dta

keep if _merge==3

cd "$path/New datasets"
save Dataset_Analysis

clear all


